package org.maxkey.portal.api.controller;
import lombok.extern.slf4j.Slf4j;
import org.maxkey.portal.core.authentication.CurrentAccount;
import org.maxkey.portal.core.cam.CurrentThreadLocal;
import org.maxkey.portal.core.cam.PageResultData;
import org.maxkey.portal.core.cam.ResultData;
import org.maxkey.portal.core.search.ParamModel;
import org.maxkey.portal.core.search.model.UserParam;
import org.maxkey.portal.model.UserInfo;
import org.maxkey.portal.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user")
@Slf4j
public class UserController extends BaseController {

    @Autowired
    private UserInfoService userInfoService;

    @PostMapping(value = "/findAll",produces="application/json;charset=utf-8")
    public ResultData findAll() {
        return userInfoService.findAll();
    }

    @PostMapping(value = "/findList",produces="application/json;charset=utf-8")
    public PageResultData findList(@RequestBody ParamModel<UserParam> searData) {

        return userInfoService.findList(searData);
    }

    @PostMapping(value = "/find/{id}")
    public ResultData find(@PathVariable Integer id) { return userInfoService.findById(id); }

    @PostMapping(value = "/info")
    public ResultData infi() {
        CurrentAccount user= CurrentThreadLocal.get();
        return userInfoService.findById(user.getId());
    }

    @PostMapping(value = "/remove/{id}")
    public ResultData remove(@PathVariable Long id) {
        return userInfoService.deleteById(id);
    }

    @PostMapping(value = "/save",produces="application/json;charset=utf-8")
    public ResultData save(@RequestBody UserInfo userInfo) {
        return userInfoService.save(userInfo);
    }

}
